%% Select local grid
idtemp=str2double(getenv('SGE_TASK_ID'));
if idtemp<workers
   u01grid_local=u01grid(jobs*(idtemp-1)+1: idtemp*jobs,:);
   u11grid_local=u11grid(jobs*(idtemp-1)+1: idtemp*jobs,:);
   u21grid_local=u21grid(jobs*(idtemp-1)+1: idtemp*jobs,:);
   u02grid_local=u02grid(jobs*(idtemp-1)+1: idtemp*jobs,:);
   u12grid_local=u12grid(jobs*(idtemp-1)+1: idtemp*jobs,:);
   u22grid_local=u22grid(jobs*(idtemp-1)+1: idtemp*jobs,:);
else
   u01grid_local=u01grid(jobs*(idtemp-1)+1: end,:);
   u11grid_local=u11grid(jobs*(idtemp-1)+1: end,:);
   u21grid_local=u21grid(jobs*(idtemp-1)+1: end,:);
   u02grid_local=u02grid(jobs*(idtemp-1)+1: end,:);
   u12grid_local=u12grid(jobs*(idtemp-1)+1: end,:);
   u22grid_local=u22grid(jobs*(idtemp-1)+1: end,:);
end

sg_local=size(u12grid_local,1);

% Components invariant across parameter values
[sgb, equalorder, ...
Ugridreduced, sgreduced,...
id_Ugridreduced,...
s_id_gridreduced, sU_id_gridreduced,...
n_U_sets, Tcoord, indices_pairs,...
numeqconstraints,coordrowseq, ...
d3, e5, f5, g3, h5, i5, l3, m5, n5 ,...
fillAeq, beq]=useful_anyparam3_ind(u01grid_local, u11grid_local, u21grid_local,u02grid_local, u12grid_local, u22grid_local, sg_local, PXY_cond);     

% Part that varies across parameter values
addpath /share/apps/mosek-9.2/9.2/toolbox/r2015aom
IdSetW=OneSide3_ind(u01grid_local, u11grid_local, u21grid_local,u02grid_local, u12grid_local, u22grid_local,...
                    sgb, equalorder, ...
                    Ugridreduced, sgreduced,...
                    id_Ugridreduced,...
                    s_id_gridreduced, sU_id_gridreduced,...
                    n_U_sets, Tcoord, indices_pairs,...
                    numeqconstraints,coordrowseq, ...
                    d3, e5, f5, g3, h5, i5, l3, m5, n5 ,...
                    fillAeq, beq);  
                      
filename = sprintf('IdSetW.%d.mat', ID);
save(filename,'IdSetW')  